﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace BiliBiliCSharpStudy.old {
    class ForEachDemo {
        public static void demo() {
            test0();
            //test1();
        }

        // 迭代器
        public static void test0() {
            int[] intArray = new int[] { 1, 2, 3, 4, 5, 6 };
            //output: System.Int32[]
            Console.WriteLine(intArray.GetType().FullName);
            Console.WriteLine(intArray is Array);
            // Array : IEnumerable
            List<int> intList = new List<int>() { 1, 2, 3, 4, 5, 6 };
            // List : IEnumerable

            IEnumerator enumerator = intArray.GetEnumerator();
            while (enumerator.MoveNext()) {
                Console.WriteLine(enumerator.Current);
            }

            enumerator.Reset();

            while (enumerator.MoveNext()) {
                Console.WriteLine(enumerator.Current);
            }
        }


        /**
         * foreach-statement:
         *      foreach ( local-variable-type identifier in expression ) embedded-statement
         */
        public static void test1() {
            int[] intArray = new int[] { 1, 2, 3, 4, 5, 6 };
            foreach (var current in intArray) {
                Console.WriteLine(current);
            }
        }
    }
}
